package com.iqismart.shorturl.handler;

import com.iqismart.shorturl.exception.ExceptionTranslateHelper;
import com.iqismart.shorturl.vo.base.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description
 * @Auther sty
 * @createTime 2019/10/14 01:43
 */
@RestControllerAdvice(basePackages = "com.iqismart.shorturl.controller.api")
public class ApiExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(ApiExceptionHandler.class);

    public ApiExceptionHandler() {
    }

    @ExceptionHandler({BindException.class})
    public Result handleException(BindException ex) {
        return ExceptionTranslateHelper.translate(ex);
    }

    @ExceptionHandler({Exception.class})
    public Result handleException(Exception ex) {
        return ExceptionTranslateHelper.translate(ex);
    }
}
